package com.chen.rocketmq.producer;

import org.apache.rocketmq.spring.core.RocketMQTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.messaging.MessagingException;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author chenyulei
 */
@RestController
public class ProducerController {
    @Autowired
    private RocketMQTemplate rocketMQTemplate;

    @GetMapping("/sendMessage")
    public String sendMessage(){
        try {
            rocketMQTemplate.convertAndSend("zhangsantopic","hello,world!");
        } catch (MessagingException e) {
            throw new RuntimeException(e);
        }
        return "message sent successfully!";
    }
}
